package com.jifujun.junbatis.base.dao;

import com.jifujun.junbatis.base.SqlBuilder;
import com.jifujun.junbatis.base.model.RootObject;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * Create with IntelliJ IDEA
 * Project Name: junbatis
 * Package Name: club.emergency.junbatis.base
 * Date: 2018/3/29 14:43
 * User: 快乐的小菌菌
 * Description:
 */
public interface GenericDao<ID, T extends RootObject> {

    @SelectProvider(type = SqlBuilder.class, method = "getById")
    T getById(ID id, Class<T> clazz);

    @SelectProvider(type = SqlBuilder.class, method = "selectOnTable")
    List<T> selectInPageForOne(String[] andArgs, Map<String, Object> selectConditionContainer, String[] orArgs, Map<String, Object> orConditionContainer, Integer pageOffset, Integer pageSize, String[] orderByArgs, Boolean inPage, Class<T> clazz);

    @SelectProvider(type = SqlBuilder.class, method = "selectOnTable")
    List<T> selectListForOne(String[] andArgs, Map<String, Object> selectConditionContainer, String[] orArgs, Map<String, Object> orConditionContainer, Integer pageOffset, Integer pageSize, String[] orderByArgs, Boolean inPage, Class<T> clazz);

    @SelectProvider(type = SqlBuilder.class, method = "selectMoreTable")
    List<T> selectListForMore(Class<T> clazz);

    @SelectProvider(type = SqlBuilder.class, method = "count")
    Integer count(String[] andArgs, Map<String, Object> selectConditionContainer, String[] orArgs, Map<String, Object> orConditionContainer, Class<T> clazz);

    @InsertProvider(type = SqlBuilder.class, method = "insertOne")
    @SelectKey(statement = "select LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = Integer.class)
    void insertOne(T t);

    @InsertProvider(type = SqlBuilder.class, method = "insertMore")
    @SelectKey(statement = "select LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = Integer.class)
    void insertMore(String[] args, Map<String, Object> valueMap, Class<T> clazz);

    @DeleteProvider(type = SqlBuilder.class, method = "deleteById")
    void deleteById(ID id, Class<T> clazz);

    @DeleteProvider(type = SqlBuilder.class, method = "deleteByCondition")
    void deleteByCondition(String[] args, Map<String, Object> deleteConditionContainer, Class<T> clazz);

    @UpdateProvider(type = SqlBuilder.class, method = "updateByCondition")
    void updateByCondition(String[] args1, Map<String, Object> updateConditionContainer, Map<String, Object> getUpdateConditionObjectMap, String[] args2, Class<T> clazz);

    @UpdateProvider(type = SqlBuilder.class, method = "removeById")
    void removeById(ID id,Class<T> clazz);
}
